-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lower the precedence of the as
operator.
#1951
Conversation
Previously, the `as` operator was being parsed like a postfix expression, and therefore being given the highest possible precedence. That caused it to bind more tightly than prefix operators, which it should not. Instead, parse it somewhat like a normal binary expression with some special-casing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️
@@ -296,6 +301,7 @@ fn lhs(p: &mut Parser, r: Restrictions) -> Option<(CompletedMarker, BlockLike)> | |||
// fn foo() { | |||
// let _ = &1; | |||
// let _ = &mut &f(); | |||
// let _ = &1 as *const i32; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's move this test to the if p.at(T![as]) {
line
// *&1 as u64; | ||
// *x(1); | ||
// &x[1]; | ||
// -1..2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's move these additional cases to an out-of-line test somewhere in test-data/parser/ok. The purpose of the inline tests is not to exhaustively check everything, but to explain what the code immediately after them does, and, for that purposes, simple cases are more useful.
Done :) |
bors r+ Thanks! |
1951: Lower the precedence of the `as` operator. r=matklad a=goffrie Previously, the `as` operator was being parsed like a postfix expression, and therefore being given the highest possible precedence. That caused it to bind more tightly than prefix operators, which it should not. Instead, parse it somewhat like a normal binary expression with some special-casing. Fixes #1851. Co-authored-by: Geoffry Song <goffrie@gmail.com>
Build succeeded |
Previously, the
as
operator was being parsed like a postfix expression, andtherefore being given the highest possible precedence. That caused it to bind
more tightly than prefix operators, which it should not. Instead, parse it
somewhat like a normal binary expression with some special-casing.
Fixes #1851.